package com.tencent.stat;

import android.content.Context;
import com.tencent.stat.common.StatCommonHelper;
import com.tencent.stat.common.StatLogger;
import com.tencent.stat.common.StatPreferences;
import com.tencent.stat.event.EventType;
import com.tencent.stat.event.e;
import java.util.Map;

class as
{
  private static volatile long f = 0L;
  private e a;
  private StatReportStrategy b = null;
  private boolean c = false;
  private Context d = null;
  private long e = System.currentTimeMillis();

  public as(e parame)
  {
    this.a = parame;
    this.b = StatConfig.getStatSendStrategy();
    this.c = parame.f();
    this.d = parame.e();
  }

  private void a(StatDispatchCallback paramStatDispatchCallback)
  {
    f.b(StatServiceImpl.e()).a(this.a, paramStatDispatchCallback);
  }

  private void b()
  {
    if ((this.a.d() != null) && (this.a.d().isSendImmediately()))
      this.b = StatReportStrategy.INSTANT;
    if ((StatConfig.j) && (NetworkManager.getInstance(StatServiceImpl.e()).isWifi()))
      this.b = StatReportStrategy.INSTANT;
    if (StatConfig.isDebugEnable())
      StatServiceImpl.f().i("strategy=" + this.b.name());
    switch (ai.a[this.b.ordinal()])
    {
    default:
      StatServiceImpl.f().error("Invalid stat strategy:" + StatConfig.getStatSendStrategy());
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 7:
    }
    do
    {
      do
      {
        return;
        c();
        return;
        aw.a(this.d).a(this.a, null, this.c, false);
        if (StatConfig.isDebugEnable())
          StatServiceImpl.f().i("PERIOD currTime=" + this.e + ",nextPeriodSendTs=" + StatServiceImpl.c + ",difftime=" + (StatServiceImpl.c - this.e));
        if (StatServiceImpl.c == 0L)
        {
          StatServiceImpl.c = StatPreferences.getLong(this.d, "last_period_ts", 0L);
          if (this.e > StatServiceImpl.c)
            StatServiceImpl.f(this.d);
          long l = this.e + StatConfig.getSendPeriodMinutes() * 60 * 1000;
          if (StatServiceImpl.c > l)
            StatServiceImpl.c = l;
          c.a(this.d).a();
        }
        if (!(StatConfig.isDebugEnable()))
          continue;
        StatServiceImpl.f().i("PERIOD currTime=" + this.e + ",nextPeriodSendTs=" + StatServiceImpl.c + ",difftime=" + (StatServiceImpl.c - this.e));
      }
      while (this.e <= StatServiceImpl.c);
      StatServiceImpl.f(this.d);
      return;
      aw.a(this.d).a(this.a, null, this.c, false);
      return;
      aw.a(this.d).a(this.a, new at(this), this.c, true);
      return;
      if (NetworkManager.getInstance(StatServiceImpl.e()).getNetworkType() == 1)
      {
        c();
        return;
      }
      aw.a(this.d).a(this.a, null, this.c, false);
      return;
    }
    while (!(StatCommonHelper.isWiFiActive(this.d)));
    a(new au(this));
  }

  private void c()
  {
    if ((aw.b().a > 0) && (StatConfig.l))
    {
      aw.b().a(this.a, null, this.c, true);
      aw.b().a(-1);
      return;
    }
    a(new av(this));
  }

  private boolean d()
  {
    if (StatConfig.h > 0)
    {
      if (this.e > StatServiceImpl.l())
      {
        StatServiceImpl.m().clear();
        StatServiceImpl.a(this.e + StatConfig.i);
        if (StatConfig.isDebugEnable())
          StatServiceImpl.f().i("clear methodsCalledLimitMap, nextLimitCallClearTime=" + StatServiceImpl.l());
      }
      Integer localInteger1 = Integer.valueOf(this.a.a().a());
      Integer localInteger2 = (Integer)StatServiceImpl.m().get(localInteger1);
      if (localInteger2 != null)
      {
        StatServiceImpl.m().put(localInteger1, Integer.valueOf(localInteger2.intValue() + 1));
        if (localInteger2.intValue() <= StatConfig.h)
          break label218;
        if (StatConfig.isDebugEnable())
          StatServiceImpl.f().e("event " + this.a.g() + " was discard, cause of called limit, current:" + localInteger2 + ", limit:" + StatConfig.h + ", period:" + StatConfig.i + " ms");
        return true;
      }
      StatServiceImpl.m().put(localInteger1, Integer.valueOf(1));
    }
    label218: return false;
  }

  public void a()
  {
    if (d());
    do
    {
      return;
      if (StatConfig.p != null)
      {
        String str = this.a.g();
        if (StatConfig.isDebugEnable())
          StatServiceImpl.f().i("transfer event data:" + str);
        StatConfig.p.onTransfer(str);
        return;
      }
      if ((StatConfig.m > 0) && (this.e >= f))
      {
        StatServiceImpl.flushDataToDB(this.d);
        f = this.e + StatConfig.n;
        if (StatConfig.isDebugEnable())
          StatServiceImpl.f().i("nextFlushTime=" + f);
      }
      if (!(NetworkManager.getInstance(this.d).isNetworkAvailable()))
        break label225;
      if (StatConfig.isDebugEnable())
        StatServiceImpl.f().i("sendFailedCount=" + StatServiceImpl.a);
      if (!(StatServiceImpl.a()))
      {
        b();
        return;
      }
      aw.a(this.d).a(this.a, null, this.c, false);
    }
    while (this.e - StatServiceImpl.b <= 1800000L);
    StatServiceImpl.e(this.d);
    return;
    label225: aw.a(this.d).a(this.a, null, this.c, false);
  }
}